<?

/*	Sitemap TEMPLATE
*	
*	renders a sitemap.
*
*	Paramaters: 	(none)	
*	
*
*					*/

global $Engine;

$map = $Engine->map->filter();

foreach( $map as $node ) {

	$menu[ $node['id'] ][] = "<li class='". (( $node['name'] == PAGE )? "active ":"" ) ."parent'><a href='/{$node['name']}'>{$node['title']}</a></li>\n";
	
	if( $node['subs'] ) 
		foreach( $node['subs'] as $sub )
			$menu[ $node['id'] ][] = render_sub( $sub );
			
			//$leader = new PAGE( $node['name'] );
			//$menu[ $node['ID'] ] = array_merge( $menu[ (int)$node['ID'] ],		$leader->render_children( "li" )		);
		

}

function render_sub( $sub ){
	
	$Pge = new PAGE( (int)$sub['id'] );

#	Should be extended to dynamic loop (multi-depth)
	return "<li ". (( $sub['name'] == PAGE )? "class='active'":"" ) ."><a href='". $Pge->parse_uri() ."'>{$sub['title']}</a></li>\n";

};

/*foreach( $_SESSION['map']['menu'] as $node ) {

	if( $node['active'] == 1 ) {
		
		$menu[ $node['ID'] ][] = "<li class='". (( $node['name'] == PAGE )? "active ":"" ) ."parent'><a href='/{$node['name']}'>{$node['title']}</a></li>\n";
		if( $node['sub'] ) {
			
			$leader = new PAGE( $node['name'] );
			$menu[ $node['ID'] ] = array_merge( $menu[ (int)$node['ID'] ],		$leader->render_children( "li" )		);
		}
	}
}*/

?>

<span id='sitemap'><? foreach( $menu as $column ) echo "<ul>" . implode( "\n", $column ) . "</ul>" ?></span>